package org.learn.spring5;


import org.junit.Test;
import org.learn.spring5.bean.Student;
import org.learn.spring5.service.UserService;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestSpring5 {
    @Test
    public void test() {
        //1.加载spring的配置文件
        ApplicationContext context = new ClassPathXmlApplicationContext("bean1.xml");
        //2.获取配置创建的对象
        //第一个参数是配置文件中配置的User对象的ID
        User user = context.getBean("user", User.class);
        System.out.println(user);
        user.addUser();
        user.getUserInfo();
    }


    @Test
    public void test2() {
        //1.加载spring的配置文件
        ApplicationContext context = new ClassPathXmlApplicationContext("bean1.xml");
        //2.获取配置创建的对象
        //第一个参数是配置文件中配置的User对象的ID
        Order order = context.getBean("order", Order.class);
        System.out.println(order);
        order.orderIno();
    }

    /**
     * P命名空间方式注入属性
     */
    @Test
    public void test3() {
        //1.加载spring的配置文件
        ApplicationContext context = new ClassPathXmlApplicationContext("bean1.xml");
        //2.获取配置创建的对象
        //第一个参数是配置文件中配置的User对象的ID
        User user = context.getBean("user1", User.class);
        System.out.println(user);
        user.addUser();
        user.getUserInfo();
    }

    /**
     * 注入属性-外部bean
     */
    @Test
    public void test4() {
        ApplicationContext context = new ClassPathXmlApplicationContext("bean2.xml");
        UserService userService = context.getBean("userService", UserService.class);
        userService.userAdd();
    }


    /**
     * 注入属性-内部bean
     */
    @Test
    public void test5() {
        ApplicationContext context = new ClassPathXmlApplicationContext("bean4.xml");
        Student student = context.getBean("student", Student.class);
        student.add();
    }


}
